package com.mk.admin.service.impl;

import com.mk.admin.mapper.DictionaryMapper;
import com.mk.admin.model.ResultDto;
import com.mk.admin.model.entity.DictionaryEntity;
import com.mk.admin.model.query.DictionaryQuery;
import com.mk.admin.model.query.ListQuery;
import com.mk.admin.model.vo.DictionaryVo;
import com.mk.admin.service.DictionaryService;
import com.mk.admin.util.DateTool;
import com.mk.admin.util.JSONCopy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class DictionaryServiceImpl implements DictionaryService {
    @Autowired
    private DictionaryMapper dictionaryMapper;

    @Override
    public ResultDto select(DictionaryQuery query) {
        return ResultDto.builder()
                .result(dictionaryMapper.select(JSONCopy.copy(query, DictionaryEntity.class)))
                .count(dictionaryMapper.count(JSONCopy.copy(query, DictionaryEntity.class)))
                .retCode("T")
                .build();
    }

    @Override
    public ResultDto selectByCodes(ListQuery query) {
        return ResultDto.data(dictionaryMapper.selectByCodes(query.getList()));
    }

    @Override
    public ResultDto add(DictionaryVo dictionaryVo) {
        dictionaryVo.setCreateTime(DateTool.format());
        dictionaryVo.setStatus(1);
        return ResultDto.data(dictionaryMapper.insert(JSONCopy.copy(dictionaryVo, DictionaryEntity.class)));
    }

    @Override
    public ResultDto update(DictionaryVo dictionaryVo) {
        dictionaryVo.setUpdateTime(DateTool.format());
        return ResultDto.data(dictionaryMapper.updateById(JSONCopy.copy(dictionaryVo, DictionaryEntity.class)));
    }

    @Override
    public ResultDto delete(int id) {
        return ResultDto.data(dictionaryMapper.deleteById(id));
    }


    @Override
    public ResultDto status(int id) {
        return ResultDto.data(dictionaryMapper.status(id));
    }
}
